﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using dal;
using DAL;

/// <summary>
///  市场焦点业务类
/// </summary>
public class TopicsBLL
{
	public TopicsBLL()
	{
		//
		//TODO: 在此处添加构造函数逻辑
		//
	}

    public string GetData()
    {
        //string key="TopicsBLL.GetData";
        //string str= (string)MemcachedTools.Get(key);
        string str = string.Empty;
        if (!string.IsNullOrEmpty(str))
        {
            return str;
        }
        CMSEntities cms = new CMSEntities();
        var id = cms.Topics.Where(x=>x.TypeId=="scjd").OrderByDescending(x => x.CTime).First().ID;
        var content = cms.Topics.First(x => x.ID == id).Content;
        var t = Newtonsoft.Json.JsonConvert.DeserializeObject<Topics>(content);
        CommonBLL cbll=new CommonBLL ();
        if(t.Stocks!=null)
        {
            StockPoolBLL stockPoolBLL = new StockPoolBLL();
            for(int i=0;i<t.Stocks.Count;i++)
            {
                try
                {
                    QgqpDAL qgqpDAL = new QgqpDAL();
                    t.Stocks[i] = qgqpDAL.GetQgqp(t.Stocks[i]);
                    var ybs = stockPoolBLL.股票研报(t.Stocks[i].Stock, 0, 10);
                    t.Stocks[i].YBLst = ybs.Select(x => new YB { id = x.id, Tile = x.Title }).ToList();
                    string stock = t.Stocks[i].Stock;
                    string bkid = cbll.LstStockType.Where(x => x.GG_CODE == stock && x.BK_CODE.StartsWith("002")).First().BK_CODE;
                    t.Stocks[i].HYMC = cbll.DicType[bkid].BK_NAME;
                }
                catch
                {
                }
            }
        }
        t.News.ImgUrl = "http://down.emoney.cn/images/scjd/" + t.News.ImgUrl;
        str = Newtonsoft.Json.JsonConvert.SerializeObject(t);
        //MemcachedTools.Add(key, str, DateTime.Now.AddHours(2));
        return str;
    }
}